﻿
Imports System.Threading
Imports osi.root.delegates
Imports osi.root.formation
Imports osi.root.connector
Imports osi.root.constants

Public Module _threadpool
    Private Sub q(ByVal d As void)
        assert(Not d Is Nothing)
        k_queue_in_managed_threadpool(Sub() void_(d))
    End Sub

    Public Sub queue_in_managed_threadpool(ByVal d As WaitCallback)
        assert(Not d Is Nothing)
        q(Sub() d(Nothing))
    End Sub

    Public Sub queue_in_managed_threadpool(ByVal d As WaitCallback, ByVal o As Object)
        assert(Not d Is Nothing)
        q(Sub() d(o))
    End Sub

    Public Sub queue_in_managed_threadpool(ByVal d As void)
        q(d)
    End Sub

    Public Sub queue_in_managed_threadpool(Of T)(ByVal d As void(Of T), ByVal i As T)
        assert(Not d Is Nothing)
        k_queue_in_managed_threadpool(Sub() void_(d, i))
    End Sub

    Public Sub queue_in_managed_threadpool(Of T)(ByVal d As Action(Of T), ByVal i As T)
        assert(Not d Is Nothing)
        q(Sub() d(i))
    End Sub

    Public Sub queue_in_managed_threadpool(Of T)(ByVal d As _do(Of T), ByVal r As pointer(Of T))
        assert(Not d Is Nothing)
        q(Sub()
              Dim i As T = Nothing
              i = d()
              eva(r, i)
          End Sub)
    End Sub

    Public Sub queue_in_managed_threadpool(Of T, RT)(ByVal d As _do(Of T, RT),
                                                     ByVal a As T,
                                                     ByVal r As pointer(Of RT))
        assert(Not d Is Nothing)
        q(Sub()
              Dim i As RT = Nothing
              i = d(a)
              eva(r, i)
          End Sub)
    End Sub

    Public Sub queue_in_managed_threadpool(Of T, RT)(ByVal d As Func(Of T, RT),
                                                     ByVal a As T,
                                                     ByVal r As pointer(Of RT))
        assert(Not d Is Nothing)
        q(Sub()
              Dim i As RT = Nothing
              i = d(a)
              eva(r, i)
          End Sub)
    End Sub
End Module
